﻿/*
 *Copyright(C) 2024 by CometGamming All rights reserved.
 *Unity版本：2022.3.33f1 
 *作者:程一峰  
 *创建日期: 2024-10-10 
 *模块说明：FSM状态机部分
 *版本: 0.1.0
*/

using Sirenix.OdinInspector;
using System;
using UnityEngine;
using Warfare.FSM;

namespace GameAIStudy
{
    /// <summary>
    /// 移动行为
    /// </summary>
    [Serializable]
    public class FSMNodeAction_Move : FSMNodeAction
    {
        public override string ActionName => "移动";

        [LabelText("停止距离")]
        public float StopDistance;

        public override void OnEnter(I_FSMContext context, I_FSMActor actor)
        {
            base.OnEnter(context, actor);
            Context = context as SamplePlayerContext;
            Actor = actor as SamplePlayer;
        }

        private SamplePlayerContext Context;
        private SamplePlayer Actor;

        public override E_MachineState Update(float deltaTime)
        {
            var curPos = Actor.transform.position;
            float distance = Vector3.Distance(curPos, Context.Target);
            if (distance < StopDistance)
                return E_MachineState.Sucess;

            Actor.SetTargetPosition(Context.Target);

            return E_MachineState.Running;
        }
    }
}
